package com.jz.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.jz.manage.TestManage;
import com.jz.model.Test;
import com.opensymphony.xwork2.ActionSupport;


public class TestAction extends ActionSupport {
	private TestManage testManage;
	
	private List<Test> testList;
	private Test test;
	private int number;
	
	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public List<Test> getTestList() {
		return testList;
	}

	public void setTestList(List<Test> testList) {
		this.testList = testList;
	}

	public Test getTest() {
		return test;
	}

	public void setTest(Test test) {
		this.test = test;
	}

	public void setTestManage(TestManage testManage) {
		this.testManage = testManage;
	}

	//----------------------------------------------------------------
	
	public String testList(){
		testList = testManage.testList();
		return SUCCESS;
	}
	
	public String testLook(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Integer aa =  (Integer) request.getAttribute("number");
		number = aa;
		test = testManage.getTest(number);
		return SUCCESS;
	}
	
	public String testSave(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String content =  request.getParameter("content");
		Test t = new Test();
		t.setNumber(number);
		t.setContent(content);
		testManage.insertTest(t);
		return SUCCESS;
	}

	public String testEdit(){
		HttpServletRequest request = ServletActionContext.getRequest();
		Integer aa =  (Integer) request.getAttribute("number");
		number = aa;
		test = testManage.getTest(number);
		return SUCCESS;
	}
}
